package com.ruoyi.index.util;

import java.util.HashMap;

/*
* 封装返回方法
* */
public class Result extends HashMap<String,Object>{

    //无参构造，当返回结果对象，内置成功信息
    private Result(){
        super.put("code",200);
        super.put("msg","success");
    }

    /*
    * 成功返回
    * */
    public static Result success(){
        return new Result();
    }
    public static Result success(String msg){
        Result result = new Result();
        result.put("msg",msg);
        return result;
    }

    /*
    * 异常返回
    * */
    public static Result error(String msg,int code){
        Result result = new Result();
        result.put("code",code);
        result.put("msg",msg);
        return result;
    }
    public static Result error(String msg){
        return error(msg,500);
    }
    public static Result error(){
        return error("异常");
    }

    public Result put(String key,Object val){
        super.put(key,val);
        return this;
    }
}
